<?php
declare (strict_types=1);

// +----------------------------------------------------------------------
// | SCApi
// +----------------------------------------------------------------------
// | 版权所有 2021~2022 贾二小 [ http://www.ipsoul.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://www.ipsoul.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免费声明 ( http://doc.ipsoul.com/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/jiaerxiao/scapi
// | github 代码仓库：https://github.com/jiaerxiao/scapi
// +----------------------------------------------------------------------

namespace app\system\service;

use app\common\service\BaseService;
use think\App;

class DicTypeService extends BaseService
{
    /**
     * 初始化
     * @param App $app
     */
    public function __construct(App $app)
    {
        parent::__construct($app, '字典类型', 'dic_type');
    }

    /**
     * 获取字典类型树
     * @author 贾二小
     * @since 2021/11/11
     */
    public function tree(): array
    {
        $map = [];
        $data = $this->list($map)->toArray();
        return get_tree($data, 0);
    }

    /**
     * 表格数据
     * @author 贾二小
     * @since 2021/11/20
     */
    public function table_list(): array
    {
        $map = [];
        return $this->list($map)->toArray();
    }

    /**
     * 保存
     * @author 贾二小
     * @since 2021/12/6
     */
    public function saving(array $paramData): void
    {
        $paramData['parentId'] = $paramData['parentId'] ?? 0;
        if (isset($paramData['id']) && $paramData['id'] > 0) {
            $this->updateById($paramData['id'], $paramData);
        } else {
            $this->insertGetId($paramData);
        }
    }
}